package com.deer.wms.base.system.web;

import com.deer.wms.base.system.model.Message.Message;
import com.deer.wms.base.system.model.Message.MessageCriteria;
import com.deer.wms.base.system.service.MessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by guo on 2019/11/25.
*/
@Api(description = "系统信息api接口")
@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping("/insert")
    public Result add(@RequestBody Message message) {
        messageService.save(message);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        messageService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Message message) {
        messageService.updateById(message);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(Integer id) {
        Message message = messageService.getById(id);
        return ResultGenerator.genSuccessResult(message);
    }

    @GetMapping("/list")
    public Result list(MessageCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<Message> list = messageService.list();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
